#!/bin/zsh

bold=$(tput bold)
regular=$(tput sgr0)

# echo "this is ${bold}bold${normal} but this isn't"

############## Define variables ###############
# Do we just need to confirm one profile or all
# Set as an environment variable: all_or_one [ values: all, one ]

# Default values
found_quantity=0
found_profile=""

# Runtime
to_find=$#

############## Script Start #############

if [[ "$all_or_one" == "all" ]]
then
	echo "Set to match all or one Profile IDs: ${bold}${all_or_one}${regular}"
fi

while [ $# -gt 0 ]
do
	echo ""
	echo "Looking for profile: ${bold}$1${regular}"

	found_profile=$(profiles list all | awk -v search=$1  '$0 ~ search {print $NF}')

	if [ -z "$found_profile" ]
	then
		echo "Profile found: ${bold}FALSE${regular}"
	fi


	if [ ! -z $found_profile ]
	then
		case "$all_or_one" in

			"one")
				echo "Set to match one profile ID"
				echo "Found a profile from list: $found_profile"
				exit 0
			;;
			"all")
				echo "Profile found: ${bold}TRUE${regular}"
				found_quantity=$(( $found_quantity + 1 ))				
			;;
			*)
				echo "Unexpected search.  Set environment variabe to either 'all' or 'one'"
				exit 1
			;;
		esac
	fi

	shift
done

if [ $found_quantity -ne $to_find ]
then
	echo "Only found $found_quantity profiles from the supplied list of $to_find"
	exit 1
fi

echo "All profiles found.  Exiting 0"
 
exit 0


#!/bin/zsh

found_profile=""

while [ $# -gt 0 ]
do
	found_profile=$(profiles list all | awk -v search=$1  '$0 ~ search {print $NF}')
	if [ ! -z $found_profile ]
	then
		echo "Found installed profile: $found_profile"
		exit 0
	else
		echo "Did not find $1" 
	fi
	shift
done
 
exit 1